package com.dragon.backstage.controller;

import com.dragon.backstage.domain.param.userOnline.UserOnlineKickOutParam;
import com.dragon.backstage.domain.param.userOnline.UserOnlineLogoutParam;
import com.dragon.backstage.domain.vo.userOnline.UserOnlineVo;
import com.dragon.backstage.service.UserOnlineService;
import com.dragon.common.annotation.AuthPermission;
import com.dragon.common.annotation.UserOperatorLog;
import com.dragon.common.enums.BusinessType;
import com.dragon.common.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 在线用户控制器
 *
 * @author dragon
 * @version 1.0
 * @date 2024/10/18 23:23
 */
@Slf4j
@RestController
@RequestMapping("/api/monitor/online")
@Tag(name = "在线用户模块接口")
public class UserOnlineController {

    @Resource
    private UserOnlineService userOnlineService;


    /**
     * 在线用户列表
     */
    @GetMapping("/list")
    @Operation(summary = "在线用户列表")
    @AuthPermission(value = "monitor.online.list")
    public AjaxResult<List<UserOnlineVo>> list() {
        return userOnlineService.userOnlineList();
    }

    /**
     * 单端/全端注销在线用户
     */
    @PostMapping("/logout")
    @Operation(summary = "单端/全端注销在线用户")
    @AuthPermission(value = "monitor.online.logout")
    @UserOperatorLog(title = "在线用户", businessType = BusinessType.USER_ONLINE_LOGOUT)
    public AjaxResult<Void> logout(@RequestBody UserOnlineLogoutParam userOnlineLogoutParam) {
        return userOnlineService.userOnlinelogOut(userOnlineLogoutParam);
    }

    /**
     * 单端/全端踢掉在线用户
     */
    @PostMapping("/kickOut")
    @Operation(summary = "单端/全端踢掉在线用户")
    @AuthPermission(value = "monitor.online.kickout")
    @UserOperatorLog(title = "在线用户", businessType = BusinessType.USER_ONLINE_KICK_OUT)
    public AjaxResult<Void> kickOut(@RequestBody UserOnlineKickOutParam userOnlineKickoutParam) {
        return userOnlineService.userOnlineKickOut(userOnlineKickoutParam);
    }

}
